package priv.mill.httpclient;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import priv.mill.httpclient.annotation.HttpPost;
import priv.mill.httpclient.util.HttpUtil;
import priv.mill.httpclient.util.ReflectUtil;

@Component("httpPostHttpAnnotationHandler")
public class PostHttpAnnotationHandler implements HttpAnnotationHandler {
	
	@Resource
	private HttpUtil httpUtil;
	
	@Resource
	private ReflectUtil reflectUtil;

	@Override
	public void resolve(Annotation annotation, Object[] args, int i) throws Exception {
		HttpPost httpGet = (HttpPost) annotation;
		String value = httpGet.value();
		String[] argNames = httpGet.argNames();
		String[] argValues = httpGet.argValues();
		
		baseResove(args, i, value, argNames, argValues);
	}

	@Override
	public String query(String url) throws Exception {
		Map<String, Object> map = new HashMap<>();
		return httpUtil.doPost(url, map);
	}

	@Override
	public String query(String url, Map<String, Object> map) throws Exception {
		return httpUtil.doPost(url, map);
	}

	@Override
	public Map<String, Object> getArgMapers(Object[] args) throws Exception {
		return reflectUtil.array2Map(args);
	}

	

}
